package com.vf.cloud.paas.app.agent.common.server.signalling.timer;

import java.util.Timer;
import java.util.TimerTask;

import com.vf.cloud.paas.app.agent.common.server.signalling.pool.PlayerPool;
import com.vf.cloud.paas.app.agent.common.server.signalling.pool.StreamerPool;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UETimerTask extends TimerTask {

	private String id;
	private Timer timer;
	private int i = 0;
	private int timeout = 5;

	public UETimerTask(String id, Timer timer, int idleTimeout) {
		this.id = id;
		this.timer = timer;
		if (idleTimeout > 0) {
			this.timeout = idleTimeout;
		}
	}

	@Override
	public void run() {
		if (PlayerPool.containsToken(id)) {
			i = 0;
		} else {
			if (i > timeout) {
				StreamerPool.killByToken(id);
				timer.cancel();
				log.info("Streamer>>>" + id + "<<< 已超时，主动退出程序.");
			} else {
				i++;
			}
		}
	}
}
